<?php
namespace app\index\model;
use think\Db;
use think\Model;

class JoinModel extends Model {

    /**
     * 记录参会信息
     * @param $data
     * @return int|string
     */
    public function joinMeetingInfo($data){
        return Db::name('Join')->insert($data);
    }

    /**
     * 判断是否是员工
     * @param $data
     */
    public function checkUser($data){
        $url = 'http://www.reachonlinemeeting.com/welcome/getbymail?email='.$data['email'];
        $responseJson = https_request($url);
        $response = json_decode($responseJson,true);
        if($response['isok'] == 'true'){
            $name = $response['data']['name'];
            if($name == $data['name']){
                 $user = Db::name('User')->where('user_name',$data['name'])->where('user_email',$data['email'])->find();;
                 if($user){
                     return $user;
                 }else{
                     $userData = array(
                         'user_name'=>$name,
                         'user_email'=>$data['email'],
                         'user_tel'=>$response['data']['mobile']
                     );
                     Db::name('User')->insert($userData);
                     $userData['user_id'] = Db::name('User')->getLastInsID();
                     return $userData;
                 }
            }
        }
        return 0;
//      return  Db::name('User')->where('user_name',$data['name'])->where('user_email',$data['email'])->find();;
    }

}